package com.yanyeori.webtest.service.impl;

import com.yanyeori.framework.core.util.JacksonUtil;
import com.yanyeori.framework.websocket.annotation.EnableWebSocketConfig;
import com.yanyeori.framework.websocket.message.WsMessageBack;
import com.yanyeori.framework.websocket.server.AbstractWebSocketServer;
import com.yanyeori.webtest.entity.clear.BankEntity;
import lombok.extern.slf4j.Slf4j;

import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

/**
 * @author chenkuan
 * @since 2021/6/3
 */
@Slf4j
@ServerEndpoint("/websocket")
@EnableWebSocketConfig
public class TestWebSocketService extends AbstractWebSocketServer {
    @Override
    protected void onOpenBack(Session session) {

    }

    @Override
    protected void onCloseBack(Session session) {

    }

    @Override
    protected void onMessageBack(WsMessageBack message) {
        log.info("topic={}, data={}", message.getTopic(), message.getData());
        BankEntity bank = JacksonUtil.parseObject(message.getData(), BankEntity.class);
        log.info("bank={}", bank);
    }

    @Override
    protected void onErrorBack(Session session) {

    }
}
